package com.gitee.pifeng.monitoring.ui.business.web.controller;

import com.gitee.pifeng.monitoring.ui.business.web.realm.MonitorUserRealm;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.xml.crypto.Data;
import java.util.Date;
import java.util.HashMap;

/**
 * <p>
 * 首页
 * </p>
 *
 * @author 张双
 * @custom.date 2023/2/10  15:34
 */
@Controller
@Api(tags = "首页")
public class IndexController {

    /**
     * <p>
     * 访问首页
     * </p>
     *
     * @return {@link ModelAndView} 首页
     * @author 张双
     * @custom.date 2023/2/10  15:34
     */
    @ApiOperation(value = "访问首页")
    @GetMapping("/index")
    public ModelAndView index() {
        return new ModelAndView("index");
    }
    @ApiOperation(value = "普通人员的首页")
    @GetMapping("/index2")
    public ModelAndView index2(){
        MonitorUserRealm principal = (MonitorUserRealm) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        Date date = new Date();
        ModelAndView modelAndView = new ModelAndView();
        HashMap<String, String> hashMap = new HashMap<>();
        if (date.getHours()<19 && date.getHours()>=14){
            modelAndView.setViewName("play/sun-rise");
            hashMap.put("mess","早上好:"+principal.getUsrname());
            modelAndView.addAllObjects(hashMap);
        } else if (date.getHours() >= 19 && date.getHours() <= 21) {
            modelAndView.setViewName("play/clock");
            hashMap.put("mess","您好:"+principal.getUsrname());
            modelAndView.addAllObjects(hashMap);
        } else if (date.getHours()>3 && date.getTime()<14){
            modelAndView.setViewName("play/night");
            hashMap.put("mess","晚上好:"+principal.getUsrname());
            modelAndView.addAllObjects(hashMap);
        }else {
            modelAndView.setViewName("play/clock");
            hashMap.put("mess","您好:"+principal.getUsrname());
            modelAndView.addAllObjects(hashMap);
        }
//        ModelAndView modelAndView = new ModelAndView("play/night");

        return modelAndView;
    }

}
